package GUI;

import ModelLayer.*;
import java.util.Random;

public class dataLoader
{
    private SalesLine product;
    private ModelLayer.Item item;
    private Customer customer;
    private DeliveryType deliveryType;
    private PaymentType paymentType;
    private ModelLayer.Staff staff;
    private ModelLayer.Discount discount;
    
    public dataLoader()
    {
//        product = new SalesLine();
//        item = new ModelLayer.Item();
//        customer = new Customer();
//        deliveryType = new DeliveryType();
//        paymentType = new PaymentType();
//        staff = new ModelLayer.Staff();
//        discount = new ModelLayer.Discount();
        
        Discounts.getInstance();
        Customers.getInstance();
        DeliveryTypes.getInstance();
        PaymentTypes.getInstance();
        Items.getInstance();
        Staffs.getInstance();
        Products.getInstance();
    }
    
    public void loadData()
    {
        for(int i=0;i<10;i++)
        {
            generateDiscount();
            discount.setId(String.valueOf(i));
            Discounts.addDiscount(discount);
            
            generateDeliveryType();
            deliveryType.setId(String.valueOf(i));
            DeliveryTypes.addDeliveryType(deliveryType);
            
            generatePaymentType();
            paymentType.setId(String.valueOf(i));
            PaymentTypes.addPaymentType(paymentType);
            
            generateCustomers();
            customer.setId(String.valueOf(i));
            Customers.addCustomer(customer);
            
            generateItems();
            item.setId(String.valueOf(i));
            Items.addItem(item);
            
            generateProducts();
            product.setId(String.valueOf(i));
            Products.addProduct(product);
            
            generateStaff();
            staff.setId(String.valueOf(i));
            Staffs.addStaff(staff);
        }
    }
    
    public void checkData()
    {
    		DeliveryTypes.printDeliveryTypes();
    		Staffs.listAllStaffs();
    		Products.printProducts();
    		Items.listAllItems();
    		Staffs.listAllStaffs();
    		PaymentTypes.printPaymentTypes();
    		Customers.printCustomers();
    }

    private void generateProducts()
    {
    	product=new SalesLine();
        product.setName(generateRandomString());
        product.setBarCode(generateRandomString());
        product.setDateAdded(generateRandomString());
        product.setLocation(generateRandomString());
        product.setDiscount(discount);
    }
    
    private void generateItems()
    {
    	item=new ModelLayer.Item();
        item.setName(generateRandomString());
        item.setPrice(generateRandomDouble());
        item.setDiscount(discount);
        item.setSalesLine(product);
    }
    
    private void generateCustomers()
    {
    	customer=new Customer();
        customer.setName(generateRandomString());
        customer.setSurname(generateRandomString());
        customer.setAddress(generateRandomString());
        customer.setPhone(generateRandomString());
        customer.setCpr(generateRandomString());
        customer.setType(generateRandomString());
        customer.setDiscount(discount);
    }
    
    private void generateDiscount()
    {
    	discount=new ModelLayer.Discount();
        discount.setName(generateRandomString());
        discount.setPercentage(generateRandomInteger());
    }
    
    private void generateStaff()
    {
    	staff=new ModelLayer.Staff();
        staff.setName(generateRandomString());
        staff.setSurname(generateRandomString());
        staff.setAddress(generateRandomString());
        staff.setPhone(generateRandomString());
        staff.setCpr(generateRandomString());
        staff.setSalary(generateRandomDouble());
        staff.setRoles(generateRandomString());
    }
    
    private void generateDeliveryType()
    {
    	deliveryType=new DeliveryType();
        deliveryType.setName(generateRandomString());
        deliveryType.setPricePerKm(generateRandomDouble());
    }
    
    private void generatePaymentType()
    {
    	paymentType=new PaymentType();
        paymentType.setName(generateRandomString());
        paymentType.setType(generateRandomString());
    }
    
    private String generateRandomString()
    {
        Random rnd = new Random();
        double d = rnd.nextDouble();
        return String.valueOf(d);
    }
    
    private int generateRandomInteger()
    {
        Random rnd = new Random();
        return rnd.nextInt();
    }
    
    private double generateRandomDouble()
    {
        Random rnd = new Random();
        return rnd.nextDouble();
    }
}
